package com.benyi.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Run {
	
	public static List<String> runCommand(String cmd) {
		try {
			Process process = Runtime.getRuntime().exec(cmd);
			InputStream in = process.getInputStream();
			BufferedReader bin = new BufferedReader(new InputStreamReader(in,"GBK"));
			List<String> msgList = new ArrayList<String>();
			String line = bin.readLine();
			while(line!=null) {
				msgList.add(line);
				line = bin.readLine();
			}
			bin.close();
			in.close();
			process.waitFor();
			return msgList;
		}catch(Exception e) {
			e.printStackTrace();
			return null;
		}
	} 
	
	public static void main(String []args) {
		List<String> rets = runCommand("cmd /c dir c: /w");
		if(rets != null) {
			for(int i=0;i<rets.size();i++) {
				System.out.println(rets.get(i));
			}
		}else {
			System.out.println("null");
		} 
	}
	
}
